define(['jquery','examHandle','text!../template/examine.html','css!../css/examine','common'],function($,examHandle,tplExamine){
	let _examine = {};
	let currentPage = 1;
	let currentType = '';
	let tpls = {
		'tplExamine' :_.template(tplExamine)
	};

	_examine.show = function(status){
		currentPage = 1;
		$('#contant').html(tpls.tplExamine());
		$('.examineType').click(function(event) {
			currentPage = 1;
			$('.examineType').removeClass('selected');
			$(this).addClass('selected');
			currentType = $(this).attr('id');
			status==0?setExamineTable(0,5,currentType):setExamineTable1(0,5,currentType);
		});
		
		$('.examineType').eq(0).click();
	}

	function reloadTable(){
		currentPage = 1;
		setExamineTable(0,5,"exIng");
	}

	window.setExamineTable = function (from,count,type){
		let _url=type=='exIng'?'/xjrest/audit/list_aduit?auditStatus=1':'/xjrest/audit/list_aduit?auditStatus=2';
		layui.use('table', function(){
			var table = layui.table;
			table.render({
				elem: '#gridRepairTable',
				url:_url,
				where: {from:from,count:count},
				limit:5,
				//cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
				skin: 'nob',
				even: '',
				cols: [[
					{field:'submitTime', title: '申请时间',align: 'center', width: type == 'exIng'?"16.66%":"12.5%"},
					{field:'userName', title: '申请人',align: 'center', width: type == 'exIng'?"16.66%":"12.5%"},
					{field:'role', title: '申请人角色',align: 'center', width: type == 'exIng'?"16.66%":"12.5%", templet: function(d){
						let role='';
						if(d.role==1){
							role='系统管理员';
						}else if (d.role==2) {
							role='街道管理员';
						}
						else if (d.role==3) {
							role='街道巡检员';
						}
						else if (d.role==4) {
							role='社区工作人员';
						}
						return role;
					}},
					{field:'phone', title: '联系电话',align: 'center', width: type == 'exIng'?"16.66%":"12.5%"},
					{field:'auditTitle', title: '申请事项',align: 'center', width: type == 'exIng'?"16.66%":"12.5%"},
					{field:'auditName', title: '审核人',align: 'center', width: "12.5%",hide: type == 'exIng'?true:false},
					{field:'auditTime', title: '审核时间',align: 'center', width: "12.5%",hide: type == 'exIng'?true:false},
					{field:'auditStatus', title: '审核状态',align: 'center', width: "12.5%",hide: type == 'exIng'?true:false, templet: function(d){
						if(d.auditStatus==2){
							return '审核通过';
						}else if (d.auditStatus==3) {
							return '审核不通过';
						}
					}},
					{field:'', title: '操作',align: 'center', width: type == 'exIng'?"16.66%":"12.5%", templet: function(d){
						let data = JSON.stringify(d).replace(/\"/g,"'");
						return `<input class="examButton" type="button" value="审核"/>`
					},hide: type == 'exEd'?true:false,event: 'setSign'}
				]],
				parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
					return {
				        "code": 0, //解析接口状态
				        "msg": res.message, //解析提示文本
				        "count": res.ret.total, //解析数据长度
				        "data": res.ret.value //解析数据列表
				    };
				},
				done: function(res, curr, count){
					table.on('rowDouble(examineTable)', function(obj){
					    let data = obj.data;
					    data.type = currentType;
					    examHandle.show(data,2);
					});
					table.on('tool(examineTable)', function(obj){
						let data = obj.data;
						data.type = currentType;
						if(obj.event === 'setSign'){
							examHandle.show(data,2);
						}
					});
					let totals = count;
		            if (totals == 0) {
		                $("#noRecordMessage").show();
		            } else {
		                $("#noRecordMessage").hide();
		            }
		            if (0 == totals % 5) {
		                totalPage = parseInt(totals / 5);
		                if (totalPage == 0){
		                     totalPage = 1;
		                }
		            } else {
		                totalPage = parseInt(totals / 5) + 1;
		            }
		            $('#pagination').paginations({
		                currentPage: currentPage,
		                totalPage: totalPage,
		                callback: function(current) {
		                    currentPage = current;
		                    current = (current - 1) * 5;
		                    setExamineTable(current,5,type);
		                }
		            });
				}
			});
		});
	}

	function setExamineTable1(from,count,type){
		let _url=type=='exIng'?'/xjrest/audit/list_aduit?auditStatus=1':'/xjrest/audit/list_aduit?auditStatus=2';
		layui.use('table', function(){
			var table = layui.table;
			table.render({
				elem: '#gridRepairTable',
				url:_url,
				where: {from:from,count:count},
				limit:5,
				//cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
				skin: 'nob',
				even: '',
				cols: [[
					{field:'submitTime', title: '申请时间',align: 'center', width: type == 'exIng'?"20%":"12.5%"},
					{field:'userName', title: '申请人',align: 'center', width: type == 'exIng'?"20%":"12.5%"},
					{field:'role', title: '申请人角色',align: 'center', width: type == 'exIng'?"20%":"12.5%", templet: function(d){
						let role='';
						if(d.role==1){
							role='系统管理员';
						}else if (d.role==2) {
							role='街道管理员';
						}
						else if (d.role==3) {
							role='街道巡检员';
						}
						else if (d.role==4) {
							role='社区工作人员';
						}
						return role;
					}},
					{field:'phone', title: '联系电话',align: 'center', width: type == 'exIng'?"20%":"12.5%"},
					{field:'auditTitle', title: '申请事项',align: 'center', width: type == 'exIng'?"20%":"12.5%"},
					{field:'auditName', title: '审核人',align: 'center', width: "12.5%",hide: type == 'exIng'?true:false},
					{field:'auditTime', title: '审核时间',align: 'center', width: "12.5%",hide: type == 'exIng'?true:false},
					{field:'auditStatus', title: '审核状态',align: 'center', width: "12.5%",hide: type == 'exIng'?true:false, templet: function(d){
						if(d.auditStatus==2){
							return '审核通过';
						}else if (d.auditStatus==3) {
							return '审核不通过';
						}
					}}
				]],
				parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
					return {
				        "code": 0, //解析接口状态
				        "msg": res.message, //解析提示文本
				        "count": res.ret.total, //解析数据长度
				        "data": res.ret.value //解析数据列表
				    };
				},
				done: function(res, curr, count){
					table.on('rowDouble(examineTable)', function(obj){
					    let data = obj.data;
					    data.type = currentType;
					    examHandle.show(data,2);
					});
					let totals = count;
		            if (totals == 0) {
		                $("#noRecordMessage").show();
		            } else {
		                $("#noRecordMessage").hide();
		            }
		            if (0 == totals % 5) {
		                totalPage = parseInt(totals / 5);
		                if (totalPage == 0){
		                     totalPage = 1;
		                }
		            } else {
		                totalPage = parseInt(totals / 5) + 1;
		            }
		            $('#pagination').paginations({
		                currentPage: currentPage,
		                totalPage: totalPage,
		                callback: function(current) {
		                    currentPage = current;
		                    current = (current - 1) * 5;
		                    setExamineTable1(current,5,type);
		                }
		            });
				}
			});
		});
	}

	window.exMap=function(lang,lat){
		$('.exaMap').show();
		var map = new BMap.Map("exaMap", { mapType: BMAP_SATELLITE_MAP });
	    var point = new BMap.Point(lang, lat);
	    var maker = new BMap.Marker(point);
	    map.addOverlay(maker);
	    map.centerAndZoom(point, 18);
	    map.enableScrollWheelZoom(true);
	}

	return _examine;
	
});